// pages/user/index.js
Page({
  data: {
    userinfo: {},
    // 被收藏的商品的数量
    collectNums: 0
  },
  //页面展示时-先获取有没有登录过。如果登录过，获取token，请求接口数据
  onShow() {
    const userinfo = wx.getStorageSync("userinfo"); //用户信息
    const collect = wx.getStorageSync("collect") || []; //收藏

    this.setData({
      userinfo,
      collectNums: collect.length
    });


  },
  //页面加载时
  onLoad() {
    this.getUserData()
  },
  //获取用户中心数据接口
  getUserData() {
    // 1 判断缓存中有没有token 
    const token = wx.getStorageSync("token");
    if (token) {
      console.log('请求个人中心接口成功');
    }
  },
  getPppp() {

    wx.openLocation({
      latitude:39.95933,
      longitude:116.29845,
      success(res) {
        console.log('eeeeeeee');
      }
    })

    // wx.getLocation({ //地理位置
    //   success(res) {
    //     console.log('------', res);
    //   }
    // })
  },
  getPhoto() {
    wx.chooseMedia({
      success(res) {
        console.log(res);
      }
    })
  },
  getAddress() {
    console.log('地址-------');
    wx.getSetting({
      success(res) {
        console.log(res.authSetting['scope.address'])
        if (res.authSetting['scope.address']) {
          console.log('-====-----');
          wx.chooseAddress({
            success: (result) => {
              console.log('========');
              console.log(result);
            },
          })
        } else {
          wx.openSetting({
            success(res) {
              console.log(res);
            }
          })
        }
      }
    })
  },
  //退出登录
  loginOut() {
    wx.clearStorage({
      success: (res) => {
        wx.reLaunch({
          url: '/pages/login/index',
        })
      },
    })
  }
})